package library;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;

public class GuiTemplatePane extends JPanel {

	private JPanel mainArea;
	private JPanel entity = null;
	private JButton showEntity = null;
	
	public GuiTemplatePane(JPanel mainArea, String buttonText) {
		
		this.showEntity = new JButton(buttonText);
		this.showEntity.addActionListener(new ShowInMainAreaActionListener());
		this.mainArea = mainArea;
		showEntity.setVisible(true);
		
		this.setLayout(new GridLayout(1,1));
		this.add(showEntity);
		
	}

	public void setEntity(JPanel entity) {
		this.entity = entity;
	}
	
	public JPanel getEntity() {
		return entity;
	}
	
	public JPanel getMainArea() {
		return mainArea;
	}

	private class ShowInMainAreaActionListener implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent e) {
			if (entity != null) {
				mainArea.removeAll();
				mainArea.add(entity);
				mainArea.revalidate();
				mainArea.repaint();
			}
		}
	}

}
